package org.blim.blackdawn;

import java.util.List;

import org.blim.blackdawn.graph.ReferenceFrame;
import org.blim.blackdawn.graph.SceneGraph;
import org.blim.blackdawn.graph.UniformAnimation;
import org.blim.blackdawn.model.Model;
import org.blim.blackdawn.model.PointLight;
import org.blim.blackdawn.model.TriangleArray;
import org.blim.blackdawn.shader.Shader;

import android.content.Context;
import android.opengl.Matrix;

public class Demo {

	public static final int BYTES_PER_FLOAT = 4;
	
	public static void createScene(
			Context context, 
			SceneGraph graph,
			List<Model> definitions,
			Shader<TriangleArray> shader) {
		int textureHandle = TextureUtils.loadTexture(
				context,
				R.drawable.bricks);
		
		TriangleArray model = new Cube(textureHandle, shader);
		PointLight light = new PointLight(new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
		
		definitions.add(model);
		
		float[] modelMatrix;
		ReferenceFrame childFrame;
		ReferenceFrame parentFrame = graph.mWorld;
		
		modelMatrix = new float[16];
		Matrix.setIdentityM(modelMatrix, 0);
		Matrix.translateM(modelMatrix, 0, 4.0f, 0.0f, -7.0f);
		childFrame = new ReferenceFrame(parentFrame, modelMatrix, model, null);

		modelMatrix = new float[16];
		Matrix.setIdentityM(modelMatrix, 0);
		Matrix.translateM(modelMatrix, 0, -4.0f, 0.0f, -7.0f);
		childFrame = new ReferenceFrame(parentFrame, modelMatrix, model, null);

		modelMatrix = new float[16];
		Matrix.setIdentityM(modelMatrix, 0);
		Matrix.translateM(modelMatrix, 0, 0.0f, 4.0f, -7.0f);
		childFrame = new ReferenceFrame(parentFrame, modelMatrix, model, null);
		
		modelMatrix = new float[16];
		Matrix.setIdentityM(modelMatrix, 0);
		Matrix.translateM(modelMatrix, 0, 0.0f, -4.0f, -7.0f);
		childFrame = new ReferenceFrame(parentFrame, modelMatrix, model, null);
		
		parentFrame = childFrame;

		modelMatrix = new float[16];
		Matrix.setIdentityM(modelMatrix, 0);
		Matrix.translateM(modelMatrix, 0, 0.0f, 0.0f, 2.0f);
		childFrame = new ReferenceFrame(parentFrame, modelMatrix, light, new UniformAnimation(0L, 10000L, 0L));
		graph.mLights.add(childFrame);
		
		parentFrame = graph.mWorld;

		modelMatrix = new float[16];
		Matrix.setIdentityM(modelMatrix, 0);
		Matrix.translateM(modelMatrix, 0, 0.0f, 0.0f, -5.0f);
		childFrame = new ReferenceFrame(parentFrame, modelMatrix, null, null);
		
		parentFrame = childFrame;

		modelMatrix = new float[16];
		Matrix.setIdentityM(modelMatrix, 0);
		childFrame = new ReferenceFrame(parentFrame, modelMatrix, model, new UniformAnimation(0L, 10000L, 0L));
		
		parentFrame = childFrame;

		modelMatrix = new float[16];
		Matrix.setIdentityM(modelMatrix, 0);
		Matrix.translateM(modelMatrix, 0, 0.0f, 0.0f, 2.0f);
		childFrame = new ReferenceFrame(parentFrame, modelMatrix, light, new UniformAnimation(7500L, 5500L, 0L));
		graph.mLights.add(childFrame);
	}
	
}
